package zjt.IO1;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class demo5 {
    public static void main(String[] args) {
       /* FileReader fileReader = new FileReader("c://b.txt");
        //1.一个字符一个字符的读取，返回当前字符；如果读完返回-1
        int read = fileReader.read();
        System.out.println((char)read);
        //2.读取字符到字符数组，返回值代表读了几个字符，如果读完返回-1
        char[] cc = new char[3];
        int len = fileReader.read(cc);
        System.out.println(len);
        System.out.println(new String(cc,0,len));*/

     /*   FileWriter fileWriter = new FileWriter("D://b.txt");
        fileWriter.write(97);
        fileWriter.write("我爱你中国".toCharArray());
        fileWriter.write("我爱你中国");
        //4.写入一个字符数组并指定从几下标开始，写入多少个
        fileWriter.write("我爱你中国".toCharArray(), 0, 3);
        //5.写入一个字符串并指定从几下标开始，写入多少个
        fileWriter.write("我爱你中国", 0, 3);
        //6.注意:字符数据必须手动刷入数据
        fileWriter.flush();
        fileWriter.close();*/

        FileReader fr = null;
        FileWriter fw = null;

        try {
            fr = new FileReader("D://a.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            fw = new FileWriter("D://b.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
        char[] cc = new char[10];
        int len;
        try {
            while((len = fr.read())!=-1){
                fw.write(cc,0,len);
                fw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
